<?php

namespace mpend\models\test;

use Yii;
use common\helpers\Url;

/**
 * 资讯模型
 * 
 * @author emhome <emhome@163.com>
 * @since 1.0
 */
class MatchSearch extends \common\models\match\Match {

    /**
     * 构建查询
     */
    public function buildQuery() {
        $query = static::find()
        ->active(static::STATUS_ACTIVE);
        $query->orderBy(['created_at' => SORT_DESC]);
        return $query;
    }

    public function getThumb() {
        $list = ['01', '02', '03', '04', '05', '06'];
        $index = \yii\helpers\ArrayHelper::getValue($list, $this->id % 6, 24);

        return Url::attach('/attachments/avatar/' . $index . '.jpg');
    }

    public function fields() {
        return [
            'id',
            'name',
            'thumb',
            'subtitle',
            'description',
            'begintime' => function() {
                return date('Y-m-d', $this->begintime) . ' 浙江省·绍兴市';
            },
            'endtime' => function() {
                return date('Y-m-d', $this->begintime);
            },
            'enroll_starttime',
            'enroll_closetime',
        ];
    }

}
